package com.shop.www.dao.Impl;

import com.shop.www.dao.UserDAO;
import com.shop.www.model.User;
import com.shop.www.ssm.BasicDao;

import java.util.List;

public class UserDAOImpl extends BasicDao implements UserDAO {


    @Override
    public User getuser(String user_name, String user_psw) {
        String sql = ("select *  from User where user_name =? and user_psw = ?");
        return (User) querysingle(sql,User.class,user_name,user_psw);
    }

    @Override
    public User getsaller(Integer user_ID) {
        String sql = ("select *  from User where user_ID =?");
        return (User) querysingle(sql,User.class,user_ID);
    }

    @Override
    public void adduser(User user) {
        String sql = ("insert into `user` values(0,?,?,?)");
        update(sql,user.getUser_name(),user.getUser_psw(),user.getRole());
    }

    @Override
    public List getsellerlist() {
        String sql = ("select *  from User where role =1");
        List list = querymany(sql,User.class);
        return list;
    }

    @Override
    public List getuserlist() {
        String sql = ("select *  from User");
        List list = querymany(sql,User.class);
        return list;
    }

    @Override
    public void updateuser(User user) {
        String sql = ("update user set state = ? where user_ID = ?");
        update(sql,user.getState(),user.getUser_ID());
    }

}
